package com.jy.rhin.infra.repo.notfication.subscribe.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jy.rhin.domain.notification.subscribe.entity.EnumSubscribeStatus;
import com.jy.rhin.domain.notification.subscribe.entity.SubscribeDO;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * @author WeiQ
 * @date 2022/6/28 14:01
 * 主题订阅信息
 */
@Data
@TableName("t_notification_subscribe")
@NoArgsConstructor
public class SubscribePO {
    public SubscribePO(SubscribeDO subscribe) {
        id = subscribe.getId();
        subscribeUid = subscribe.getSubscribeUid();
        subscriberCode = subscribe.getSubscriberCode();
        topicExp = subscribe.getTopicExp();
        queryExp = subscribe.getQueryExp();
        status = subscribe.getStatus().name();
        createBy = subscribe.getCreateBy();
        createTime = subscribe.getCreateTime();
        updateBy = subscribe.getUpdateBy();
        updateTime = subscribe.getUpdateTime();
    }

    public SubscribeDO toDO() {
        SubscribeDO subscribe = new SubscribeDO();
        subscribe.setId(this.id);
        subscribe.setSubscribeUid(this.subscribeUid);
        subscribe.setSubscriberCode(this.subscriberCode);
        subscribe.setTopicExp(this.topicExp);
        subscribe.setQueryExp(this.queryExp);
        subscribe.setStatus(EnumSubscribeStatus.valueOf(this.status));
        subscribe.setCreateBy(this.createBy);
        subscribe.setCreateTime(this.createTime);
        subscribe.setUpdateBy(this.updateBy);
        subscribe.setUpdateTime(this.updateTime);
        return subscribe;
    }

    @TableId
    private Long id;
    /**
     * 订阅标识号
     */
    @TableField("subscribe_uid")
    private String subscribeUid;
    /**
     * 订阅者代码
     */
    @TableField("subscriber_code")
    private String subscriberCode;
    /**
     * 订阅主题表达式
     */
    @TableField("topic_exp")
    private String topicExp;
    /**
     * 使用的预存查询函数表达式
     */
    @TableField("query_exp")
    private String queryExp;
    /**
     * 订阅状态;SUBSCRIBED:已订阅, CANCEL:已取消,PAUSED:已暂停
     */
    @TableField("status")
    private String status;
    /**
     * 创建人
     */
    @TableField("create_by")
    private String createBy;
    /**
     * 创建时间
     */
    @TableField("create_time")
    private Date createTime;
    /**
     * 更新人
     */
    @TableField("update_by")
    private String updateBy;
    /**
     * 更新时间
     */
    @TableField("update_time")
    private Date updateTime;
}
